home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Modules / BackSpaceModules / Source / QizColorView / QixColorView.m < prev    next >
Text File  |  1991-11-07  |  4KB  |  209 lines

  1.  
  2. #import    <stdlib.h>
  3. #import    <math.h>
  4. #import    <appkit/Application.h>
  5. #import    <appkit/Slider.h>
  6. #import    <appkit/Button.h>
  7. #import    <appkit/NXImage.h>
  8. #import <appkit/color.h>
  9. #import    <dpsclient/wraps.h>
  10. #import    "QixColorView.h"
  11.  
  12. /**********************************************************************/
  13.  
  14. #define    LEFT        ( 100 )
  15. #define    RIGHT        ( 101 )
  16. #define    UP            ( 102 )
  17. #define    DOWN        ( 103 )
  18.  
  19. #define    INITLEN        ( 55 )                //    Initial qix tail length.
  20.  
  21. #define    A_BASE_INC    ( 5 )                //    Default distance to move the
  22.                                         //    "A" point of a qix structure.
  23. #define    B_BASE_INC    ( 8 )                //    Default distance to move the
  24.                                         //    "B" point of a qix structure.
  25.  
  26. /**********************************************************************/
  27.  
  28.  
  29. @implementation QixColorView
  30.  
  31. /**********************************************************************/
  32.  
  33. - newWindow
  34. {
  35.     [ self resetQix : &head : NO ];
  36.     [ self resetQix : &tail : YES ];
  37.     
  38.     return self;
  39. }
  40.  
  41. /**********************************************************************/
  42.  
  43. - (const char *) windowTitle
  44. {
  45.     return ( const char * ) "Qix Lines";
  46. }
  47.  
  48. /**********************************************************************/
  49.  
  50. - initFrame : ( const NXRect * ) frameRect
  51. {
  52.     [ super initFrame : frameRect ];
  53.     
  54.     [ self setOpaque : YES ];
  55.     [ self setClipping : NO ];
  56.     
  57.     [ self resetQix : &head : NO ];
  58.     [ self resetQix : &tail : YES ];
  59.     
  60.     // added for color by Don Yacktman 11/7/91
  61.     hue = 0; // starting hue
  62.     
  63.     return self;
  64. }
  65.  
  66. /**********************************************************************/
  67.  
  68. - sizeTo : ( NXCoord ) width : ( NXCoord ) height
  69. {
  70.     [ super sizeTo : width : height ];
  71.     
  72.     [ self resetQix : &head : NO ];
  73.     [ self resetQix : &tail : YES ];
  74.     
  75.     return self;
  76. }
  77.  
  78. /**********************************************************************/
  79.  
  80. - resetQix : ( QIX * ) qix : ( BOOL ) resetControls
  81. {
  82.     if( resetControls == YES )
  83.         tailLen = INITLEN;
  84.     
  85.     qix->pointA.x = bounds.size.width / 3.0;
  86.     qix->pointA.y = bounds.size.height / 3.0;
  87.     qix->pointA.x_dir = RIGHT;
  88.     qix->pointA.y_dir = DOWN;
  89.     qix->pointA.x_inc = A_BASE_INC;
  90.     qix->pointA.y_inc = A_BASE_INC;
  91.     qix->pointA.orig_inc = A_BASE_INC;
  92.     
  93.     qix->pointB.x = bounds.size.width / 2.0;
  94.     qix->pointB.y = bounds.size.height / 2.0;
  95.     qix->pointB.x_dir = LEFT;
  96.     qix->pointB.y_dir = UP;
  97.     qix->pointB.x_inc = B_BASE_INC;
  98.     qix->pointB.y_inc = B_BASE_INC;
  99.     qix->pointB.orig_inc = B_BASE_INC;
  100.     
  101.     return self;
  102. }
  103.  
  104. /**********************************************************************/
  105.     
  106. - setQixPoint : ( MVPOINT * ) point
  107. {
  108.     if( point->x >= bounds.size.width )
  109.     {
  110.         point->x_dir = LEFT;
  111.         point->x_inc = point->orig_inc;
  112.     }
  113.     else if( point->x <= 0 )
  114.         point->x_dir = RIGHT;
  115.     
  116.     if( point->x_dir == RIGHT )
  117.     {
  118.         point->x += point->x_inc;
  119.         point->x_inc -= .009;
  120.     }
  121.     else
  122.     {
  123.         point->x -= point->x_inc;
  124.         point->x_inc += .03;
  125.     }
  126.  
  127.     if( point->y >= bounds.size.height )
  128.     {
  129.         point->y_dir = DOWN;
  130.         point->y_inc = point->orig_inc;
  131.     }
  132.     else if( point->y <= 0 )
  133.         point->y_dir = UP;
  134.         
  135.     if( point->y_dir == UP )
  136.     {
  137.         point->y += point->y_inc;
  138.         point->y_inc -= .009;
  139.     }
  140.     else
  141.     {
  142.         point->y -= point->y_inc;
  143.         point->y_inc += .06;
  144.     }
  145.         
  146.     return self;
  147. }
  148.  
  149. /**********************************************************************/
  150.  
  151. - drawQix : ( QIX ) qix
  152. {
  153.     PSsetlinewidth( 0.5 );
  154.  
  155.     PSmoveto( qix.pointA.x, qix.pointA.y );
  156.     PSlineto( qix.pointB.x, qix.pointB.y );
  157.     PSstroke( );
  158.     
  159.     return self;
  160. }
  161.  
  162. /**********************************************************************/
  163.  
  164. - oneStep
  165. {
  166.     NXColor drawColor; // added 11/7/91 by Don Yacktman for COLOR
  167.     
  168.     if( tailLen )
  169.         --tailLen;
  170.     else
  171.     {
  172.         PSsetgray( NX_BLACK );
  173.         [ self drawQix : tail ];
  174.         [ self setQixPoint :  &tail.pointA ];
  175.         [ self setQixPoint :  &tail.pointB ];
  176.     }
  177.     
  178.     // PSsetgray( NX_WHITE );
  179.     // Next three lines for COLOR added 11/7/91 by Don Yacktman
  180.     drawColor = NXConvertHSBToColor(hue/256.0, 1.0, 1.0);
  181.     hue = (hue + 1) % 256;
  182.     NXSetColor(drawColor);
  183.     
  184.     [ self drawQix : head ];
  185.     [ self setQixPoint : &head.pointA ];
  186.     [ self setQixPoint : &head.pointB ];
  187.     
  188.     return self;
  189. }
  190.  
  191. /**********************************************************************/
  192.  
  193. - drawSelf : ( NXRect * ) r : ( int ) count
  194. {     
  195.     if (!r || !count)
  196.         return self;
  197.         
  198.     PSsetgray( NX_BLACK );
  199.     
  200.     NXRectFill( r );
  201.     
  202.     return self;
  203.     
  204. }
  205.  
  206. /**********************************************************************/
  207.  
  208. @end
  209.